<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <ul>
        <li>111</li>
        <li>222</li>
        <li>333</li>
    </ul>
    <button>新增一个li 444</button>
    <script>
        var oLis = document.querySelectorAll('li');
        var oBtn = document.querySelector('button');
        var oUl = document.querySelector('ul');

        for(var i = 0; i < oLis.length; i++){
            oLis[i].onclick = function(){
                console.log(this.innerText);
            }
        }

        // 新增的li 444 在绑定事件的时候还没有，是后添加的。我们称之为未来元素
        oBtn.onclick = function(){
            var newLi = document.createElement('li');
            newLi.innerText = 444;
            oUl.appendChild(newLi);
            // 未来元素添加创建之后，需要手动重新绑定事件
            newLi.onclick = function(){
                console.log(this.innerText);
            }
        }

    </script>
</body>
</html>